<?php

	//Wordpress Help
	
	//Create Widget in "default-widgets.php" File
	
	class jpp_latest_posts extends WP_Widget 
	{
		function __construct() 
		{
			parent::__construct(
				'ltst_pst', // Base ID
				'Latest Posts', // Widget Name Which Is Display in Widget Area
				array( 'description' => __( 'Get Latest Post', 'text_domain' ), ) // Widget Description Which Is Display in Widget Area
			);
		}
		
		public function widget( $args, $instance )
		{
			$title = apply_filters( 'widget_title', $instance['title'] );
			echo $args['before_widget'];
			$cat_id = get_cat_ID( 'Latest Posts' );
			//$args = array('posts_per_page'=> 2,'category'=> $cat_id ,'post_type'=> 'post', );
			$posts = query_posts( 'cat='.$cat_id.'&posts_per_page=2' );
			ob_start();
			//HTML Code Whic is display in place of widget Call
			$output_string = ob_get_contents();
			ob_end_clean();
			echo $output_string;
			echo $args['after_widget'];
		}
		
		public function form( $instance ) 
		{
			if ( isset( $instance[ 'title' ] ) ) 	
			{
				$title = $instance[ 'title' ];
			}
			else 
			{
				$title = __( 'New title', 'text_domain' );
			}
			?>
            <p>
              <label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
              <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
            </p>
            <?php 
        }
		public function update( $new_instance, $old_instance ) 
		{
			$instance = array();
			$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
			return $instance;
		 }
	}
	
	function latest_posts() 
	{
    	register_widget( 'jpp_latest_posts' );
	}
	add_action( 'widgets_init', 'latest_posts' );
	
	//Create Shortcodes in "functions.php" File 
	//services atts = "value To Pass"]Content[/services] 	# Define in Posts
	//echo do_shortcode( '[fluidslideshow]' )  				# Define In Code(PHP) Files
	
	function jp_postfromcategory( $atts,$content = null )
	{
		extract( shortcode_atts( array( 'cat_name' => 'something',), $atts ) );
		$cat_id = get_cat_ID( $cat_name );
		$posts = query_posts( 'cat='.$cat_id.''  );
		ob_start();
		?>
			 <h1><?php echo $content; ?></h1>
			 <ul>
			 <?php
			foreach($posts as $post)
			{
			?>
				<li><a href="<?php echo $post->guid; ?>"><?php echo $post->post_title; ?></a></li>
			<?php
			}
			 ?>
			 </ul>
		<?php
		$output_string = ob_get_contents();
		ob_end_clean();
		return $output_string;
	}
	add_shortcode( 'services', 'jp_postfromcategory' );

	//Plug In Development
	/* Plugin Name: Clients Plugins
	Plugin URI: http://www.keyideasinfotech.com/
	Description: Client Management Plugin
	Version: 1.0
	Author: Jitendra Prajapati
	Author URI: http://www.keyideasinfotech.com/
	License: GPLv2 or later
	*/

	function function_name() 
	{
	   global $wpdb;
	   $table_name = $wpdb->prefix . "tablename";
	   $sql = "Create Table Query";
	   $wpdb->query($sql);
	}
	register_activation_hook(__FILE__, 'function_name');

	function function_name() 
	{	
		global $wpdb;
		$table_name = $wpdb->prefix . "tablename";;
		$sql = "DROP TABLE ". $table_name;
		$wpdb->query($sql);
	}
	register_deactivation_hook(__FILE__, 'function_name');

	//Include JavaScripts files in theme
	add_action('wp_enqueue_scripts', 'clnt_scripts');
	function clnt_scripts() 
	{
	  wp_enqueue_script('jquery');
	
	  wp_register_script('slidesjs_core', plugins_url('js/js_name.js', __FILE__),array("jquery"));
	  wp_enqueue_script('slidesjs_core');
	}
	
	//Include CSS Files in theme
	add_action('wp_enqueue_scripts', 'clnt_styles');
	function clnt_styles() 
	{
		wp_register_style('slidesjs_example', plugins_url('css/css_name', __FILE__));
		wp_enqueue_style('slidesjs_example');
	}
	
	//Create Admin Menu Function
	add_shortcode("my_clients", "my_clients_function");
	function my_clients_function() 
	{
	  return "<h1>Hello Shortcodes</h1>";
	}
	
	//Create Admin Sub-Menu Function
	add_action( 'admin_menu', 'register_my_custom_menu_page' );	
	function register_my_custom_menu_page()
	{
	  //add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
		add_menu_page( 'Client Management', 'Clients', 'manage_options', 'clients/clientlist.php', '', plugins_url( 'clients/images/clients.png' ), 26 );
	  //add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );	
		add_submenu_page( 'clients/clientlist.php', 'Add Client', 'Add Client', 'manage_options', 'clients/addclient.php', $function );
	}


?>